package pl.javarsovia.javarsovia4android.domain;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class Conference {

	private List<Room> rooms;
	private Map<PartnerType, List<Partner>> partnersByTypes;
	private List<Slot> slots;

	public Conference partners(List<Partner> partners) {
		partnersByTypes = Partner.groupByTypes(partners);
		return this;
	}

	public Conference rooms(List<Room> rooms) {
		this.rooms = rooms;
		return this;
	}

	public List<Room> getRooms() {
		return rooms;
	}

	public List<Partner> getPartnersWithType(PartnerType type) {
		return partnersByTypes.get(type);
	}

	public List<Speaker> getSpeakers() {
		List<Speaker> speakers = new ArrayList<Speaker>();
		for (Room room : rooms) {
			for (Lecture lecture : room.getLectures())
				addSpeakerIfExists(speakers, lecture);
		}
		Collections.sort(speakers);
		return speakers;
	}

	private void addSpeakerIfExists(List<Speaker> speakers, Lecture lecture) {
		if (lecture.getSpeaker() != null)
			speakers.add(lecture.getSpeaker());
	}

	public List<Slot> getSlots() {
		return slots;
	}

	public Conference slots(List<Slot> slots) {
		this.slots = slots;
		return this;
	}
}
